import React, { ChangeEventHandler, useState, } from 'react';
import './Login.scss';
import { useNavigate } from 'react-router-dom'
import { Input, Button } from 'antd';
import axios from '@/axios/index'
import GlobalUtil from '../../utils/GlobalUtil';
import auth from '@/utils/auth';
const Login: React.FC = (param) => {
  let currentUrl2 = window.location.href;
  // const path = currentUrl2.split('#')
  const navigate = useNavigate();
  const [state, setState] = useState({
    userName: '',
    passWord: ''
  })
  async function clickBtn() {
    // const { data } = await axios.post('loginByPw2', {
    //   cipher: "YGyglLuV6DDYRp8VkJGhYzDVG7n3bE6eR791gFpDRt8iJ9fWz9Ja4YZ/zVn7ZRExvQfxbRYB14t0boqHBe00qw==",
    //   username: "YWRtaW4="
    // })
    // GlobalUtil.setLocalStorage('loginByPw', data)
    auth.setPermission([123])
    navigate('/home/tabletest', { state: { name: 'xxx', ha: '63565' } })

  }
  function onChange(e: any) {
    if (!e.nativeEvent.data) return
    setState(state => {
      state[e.target.name] += e.nativeEvent.data
      return { ...state }
    })

  }
  return (
    <div className='Login' >
      <h1 className='title'>
        登录
      </h1>
      <div className='box'>
        <div className='list'>
          <Input
            placeholder="请输入用户名"
            name='userName'
            value={state.userName}
            onChange={onChange}
          />
        </div>
        <div className='list'>
          <Input
            placeholder="请输入用户名"
            value={state.passWord}
            name='passWord'
            onChange={onChange}
          />
        </div>
        <div className='btn'>
          <Button type="primary" onClick={clickBtn}>
            登录
          </Button>
        </div>
      </div>
    </div>
  )
}

export default Login;
